:-use_module(model_routines).

th_g:-
	driven(g,wastes).

th_d:-
	driven(d,wastes).

th_v:-
	driven(v,wastes).

waitfor(X):-thread_get_message(msgq,X),thread_send_message(msgq,X).

solid(_,wastes).
allowed(v,drive):-mwrite(" v is driving\n").
allowed(v,load):-thread_get_message(msgq,loaded(wastes)).
allowed(v,drill):-thread_get_message(msgq,drilled(wastes)).

allowed(g,load):-thread_send_message(msgq,loaded(wastes)),mwrite(" g is loading\n").
allowed(g,drill):-thread_get_message(msgq,drilled(wastes)).

allowed(d,drill):-thread_send_message(msgq,drilled(wastes)),mwrite(" d is drilling\n").

drilled(X,wastes):-
	mwritef("%w: drilling...\n",[X,_]),
	solid(X,wastes),
	allowed(X,drill),
	mwritef("%w: drilled\n",[X,_]).
loaded(X,wastes):-
	mwritef("%w: loading...\n",[X,_]),
	drilled(X,wastes),
	allowed(X,load),
	mwritef("%w: loaded\n",[X,_]).
driven(X,wastes):-
	mwritef("%w: driving...\n",[X,_]),
	loaded(X,wastes),
	allowed(X,drive),
	mwritef("%w: driven\n",[X,_]).

